<?php
declare (strict_types=1);

namespace app\middleware;

class PhoneCheck
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        $phone_number = $request->param('phone');
        $g = "/^1[3456789]\d{9}$/";
        $g2 = "/^19[89]\d{8}$/";
        $g3 = "/^166\d{8}$/";
        if (preg_match($g, $phone_number)) {
            return $next($request);
        } else if (preg_match($g2, $phone_number)) {
            return $next($request);
        } else if (preg_match($g3, $phone_number)) {
            return $next($request);
        }
        return app('json')->json_error('手机号错误');
    }
}
